#-------------------------------------------------------------------------------
# Name:        Objects
# Purpose:
#
# Author:      Pablo
#
# Created:     27/04/2013
# Copyright:   (c) Monxcleyr Productions 2013
# Licence:     GPL v3
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import pygame

class Player():

  """class comment"""

  def __init__(self, pos, sprite, imagehandler):
    self.worldpos = pos
    self.sprite = sprite
    self.imagehandler = imagehandler
    self.spritesize = (4,5)
    self.getSpriteFrames()
    self.rect = pygame.Rect(self.worldpos, self.framesize)



  def getSpriteFrames(self):
    size = self.imagehandler.getSprite(self.sprite).get_size()
    framesize = (size[0] / self.spritesize[0], size[1] / self.spritesize[1])
    self.framesize = framesize
    self.frames = []

    for j in range(0, self.spritesize[1]):
      for i in range(0, self.spritesize[0]):
        self.frames.append((i * self.framesize[0], j * self.framesize[1], self.framesize[0], self.framesize[1]))


  def move(self, direction):
    self.worldpos = (self.worldpos[0] + direction[0], self.worldpos[1] + direction[1])
    self.rect = pygame.Rect(self.worldpos, self.framesize)


  def draw(self, surface):

    frameindex = 0
    frame = self.frames[frameindex]
    size = (frame[2], frame[3])
    image = pygame.Surface(size, pygame.SRCALPHA)

    image.blit(self.imagehandler.getSprite(self.sprite), (-frame[0], -frame[1]))

    surface.blit(image, self.worldpos)

  def checkInRange(self, stations):
    """ Checks what station you are in range of, and if it is active"""
    for station in stations.stationList:
      if self.rect.colliderect(station.rect) and station.event == 1:
        station.work_required = station.work_required - 1
        station.working = True
      else:
        station.working = False
      if station.work_required <= 0:
        station.event = 2
        stations.delEntity(station)
        print "station deleted"










